package job;

import org.springframework.beans.factory.annotation.Autowired;

import presentation.Printer;
import bean.Hand;
import bean.Table;
import calculator.BridgeCalc;

public class CalculatorJob implements Runnable {

	@Autowired
	private Table table;

	@Override
	public void run() {

		Printer.println("---Start Job---");
		for (Hand h : table.getHands()) {
			h.sortHand();
		}
		
		Printer.printTable(table);
		if (!table.validate()) {
			Printer.println("Table invalid: duplicate cards");
			return;
		}
		BridgeCalc bc = new BridgeCalc();
		int result =0;
		try {
			result = bc.calc(table);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Printer.printResult(result);
		Printer.println("---End Job---");
	}

	public Table getTable() {
		return table;
	}

	public void setTable(Table table) {
		this.table = table;
	}
}
